{if $action == "list"}
<table>
    <thead>
        <tr class="odd">
            <th scope="col" abbr="Codice">
                Codice
            </th>
            <th scope="col" abbr="Home">
                Nome
            </th>
            <th scope="col" abbr="Home Plus">
                Descrizione
            </th>
            <th scope="col" abbr="Business">
                Up
            </th>
            <th scope="col" abbr="Business Plus">
                Down
            </th>
            <th>
                Pubblica
            </th>
            <th scope="col" abbr="Business">
                Edit
            </th>
            <th scope="col" abbr="Business Plus">
                Delete
            </th>
        </tr>
    </thead>
    <tbody>
    	{section name=i loop=$list}
        <tr {cycle values=""",class="odd""} id="{$list[i]->getId()}">
            <td>
                {$list[i]->getId()}
            </td>
            <td>
                {$list[i]->getNome()}
            </td>
            <td>
                {$list[i]->getDescrizione()}
            </td>
            <td>
            	<a href="#"><img src="css/img/up.png"></a>
            </td>
            <td>
                <a href="#"><img src="css/img/down.png"></a>
            </td>
            <td>
            	{if $list[i]->getVisibile() == 1}
                <a class="linkaction" href="./?pg={$pg}&action=visible&id={$list[i]->id}&visible=0"><img src="css/img/visible.png"></a>
				{else}
				<a class="linkaction" href="./?pg={$pg}&action=visible&id={$list[i]->id}&visible=1"><img src="css/img/novisible.png"></a>
				{/if}
            </td>
            <td>
                <a class="linkaction" href="./?pg={$pg}&action=modify&id={$list[i]->id}"><img src="css/img/edit.png"></a>
            </td>
            <td>
                <a class="linkaction"  href="./?pg={$pg}&action=delete&id={$list[i]->id}"><img src="css/img/delete.png"></a>
            </td>
        </tr>
		{/section}
    </tbody>
</table>

<div id="tnt_pagination">
    <span class="disabled_tnt_pagination">Prev</span>
    <a href="#1">1</a>
    <a href="#2">2</a>
    <a href="#3">3</a>
    <span class="active_tnt_link">4</span>
    <a href="#5">5</a>
    <a href="#6">6</a>
    <a href="#7">7</a>
    <a href="#8">8</a>
    <a href="#9">9</a>
    <a href="#10">10</a>
    <a href="#forwaed">Next</a>
</div>
{literal}
<script type="text/javascript" language="JavaScript">
	window.addEvent('domready', function(){
		
		$('toprightmenu').set('html', {/literal}'{$toprightmenu}'{literal});
		
		$$('table tr').each(function(el){

					odd = null;
					el.addEvent('mouseenter',function(){
						
						odd = false;
						if(el.hasClass('odd')){
							el.removeClass('odd');
							odd = true;
						} 
						if(!el.hasClass('highlight')){ 
							el.addClass('highlight'); 
						} 
					});
					el.addEvent('mouseleave',function(){
						if(odd){
							el.addClass('odd');
						}
						if(el.hasClass('highlight')){ 
							el.removeClass('highlight'); 
						} 
					});
				});
				
				var box = $('messagebox');
                box.setStyle('opacity', '0');
                var myFx = new Fx.Tween(box, {
                    property: 'opacity',
                    duration: 1000
                });
				
				// Set Visible and novisible product 
				$$('.linkaction').addEvent('click', function(e) {
					new Event(e).stopPropagation();
					new Event(e).stop();
					var urlTo = e.target.parentNode;//.parentNode.href;
					
					var req = new Request.HTML({
						url: urlTo+'&ajax=on',
            			evalScript: true,
 						update: $('content'),

						/**
						 * Mostra un messaggio di caricamento pagina.
						 */
						onRequest: function(){
							box.addClass('info');
                            box.set('html', 'Salvataggio in corso...');
							myFx.start(0, 1);
						},
						/**
						 * Inserisce nel div specificato la pagina richiesta
						 * @param {Object} html
						 */
						onSuccess: function(response){
							myFx.wait(500).chain(function(){
								myFx.start(1,0).chain(function(){
									box.removeClass('info');	
								});
								
							});
						},
						/**
						 * Se la request fallisce mostra l'errore
			 			*/
						onFailure: function(){
							box.removeClass('info');	
							box.addClass('error');
							box.set('html', 'Errore riprovare...');
							myFx.wait(2000).chain(function(){
								myFx.start(1,0).chain(function(){
									box.removeClass('error');	
								});
								
							});                        
						}
					});
					req.send();
				});
							
				
			$('add').addEvent('click', function(e){
				new Event(e).stop();
							
				var urlTo = e.target.parentNode;//.parentNode.href;
				var req = new Request.HTML({
					url: urlTo + '&ajax=on',
					evalScript: true,
					update: $('content'),
								
					/**
					* Mostra un messaggio di caricamento pagina.
					*/
					onRequest: function(){
					},
					/**
				 	* Inserisce nel div specificato la pagina richiesta
					* @param {Object} html
					*/
					onSuccess: function(response){
					},
					/** 
					* Se la request fallisce mostra l'errore
				 	*/
					onFailure: function(){
					}
			});
			req.send();
		});
		
	});

</script>

{/literal}
{/if}

{if $action == "add"}
<form id="formadd" action="./?pg={$pg}&action=list" method="post">
	<fieldset class="fancy-left">
		<legend>Aggiungi un prodotto: </legend>
		<ol>
			<li>
				<label for="nome">Nome:</label>
				<input class="text" type="text" name="nome" />
			</li>
			<li>
				<label for="descrizione">Descrizione: </label>		
				<textarea class="mceEditor" cols="20" rows="10" name="descrizione"></textarea>
			</li>
		</ol>
		</fieldset>
		<fieldset class="fancy-left submit">
			<input class= "button" type="submit" name="submitadd" value="Aggiungi"/>
			<input class="button" type="submit" name="cancel" value="Annulla"/>
		<fieldset>
</form>
{literal}
<script type="text/javascript" language="JavaScript">
	window.addEvent('domready', function(){
		$('toprightmenu').set('html', {/literal}'{$toprightmenu}'{literal});
		
		
		$('formadd').addEvent('submit', function(e){
				tinyMCE.triggerSave(true,true);
				new Event(e).stop();


				var req = new Request.HTML({
					url: $('formadd').action + '&ajax=on',
					method: 'post',
					evalScripts: true,
					update: $('content'),
								
					onRequest: function(){
					},
					onSuccess: function(response){
					},
					onFailure: function(){
					}
			});
			req.post($('formadd'));
		});
		
		
		
		tinyMCE.init({
			mode : "textareas",
			theme : "advanced",
			editor_selector : "mceEditor",
			editor_deselector : "mceNoEditor",
			plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups",
			
			// Theme options
			//theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
			//theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
			theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
			theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr",
			theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : true,

			// Example word content CSS (should be your site CSS) this one removes paragraph margins
			content_css : "css/word.css",
	
			// Drop lists for link/image/media/template dialogs
			template_external_list_url : "lists/template_list.js",
			external_link_list_url : "lists/link_list.js",
			external_image_list_url : "lists/image_list.js",
			media_external_list_url : "lists/media_list.js",
	
			// Replace values for the template plugin
			template_replace_values : {
				username : "Some User",
				staffid : "991234"
			}
		});
		
		
	});
</script>

{/literal}
{/if}



{if $action == "modify"}
<form id="formmodify" action="./?pg={$pg}&action=list" method="post">
	<fieldset class="fancy-left">
		<legend>Modifica prodotto: </legend>
		<ol>
			<li>
				<label for="nome">Nome:</label>
				<input class="text" type="text" name="nome" value="{$object->getNome()}"/>
			</li>
			<li>
				<label for="descrizione">Descrizione: </label>		
				<textarea class="mceEditor" cols="20" rows="10" name="descrizione">{$object->getDescrizione()}</textarea>
			</li>
		</ol>
		</fieldset>
		<fieldset class="fancy-left submit">
			<input name="id" type="hidden" value="{$object->getId()}" />
			<input class= "button" type="submit" name="submitmodify" value="Modifica"/>
			<input class="button" type="button" name="cancel" value="Annulla"/>
		<fieldset>
</form>
{literal}
<script type="text/javascript" language="JavaScript">
	window.addEvent('domready', function(){
		$('toprightmenu').set('html', {/literal}'{$toprightmenu}'{literal});
		
		
		$('formmodify').addEvent('submit', function(e){
				tinyMCE.triggerSave(true,true);
				new Event(e).stop();


				var req = new Request.HTML({
					url: $('formmodify').action + '&ajax=on',
					method: 'post',
					evalScripts: true,
					update: $('content'),
								
					onRequest: function(){
					},
					onSuccess: function(response){
					},
					onFailure: function(){
					}
			});
			req.post($('formmodify'));
		});
		
		
		
		tinyMCE.init({
			mode : "textareas",
			theme : "advanced",
			editor_selector : "mceEditor",
			editor_deselector : "mceNoEditor",
			plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups",
			
			// Theme options
			//theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
			//theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
			theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
			theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr",
			theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : true,

			// Example word content CSS (should be your site CSS) this one removes paragraph margins
			content_css : "css/word.css",
	
			// Drop lists for link/image/media/template dialogs
			template_external_list_url : "lists/template_list.js",
			external_link_list_url : "lists/link_list.js",
			external_image_list_url : "lists/image_list.js",
			media_external_list_url : "lists/media_list.js",
	
			// Replace values for the template plugin
			template_replace_values : {
				username : "Some User",
				staffid : "991234"
			}
		});
		
		
	});
</script>

{/literal}
{/if}




{literal}
<script type="text/javascript" language="JavaScript">
	window.addEvent('domready', function(){
		
		$('breadCrumb').set('html', {/literal}'{$breadCrumb}'{literal});
		
	 	new Asset.javascript('js/inputFocus.js');
	});
</script>
{/literal}